package main.java.indi.zyj.sword;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;

public class ValidateBookSequences {


    public boolean validateBookSequences(int[] putIn, int[] takeOut) {

        Deque<Integer> stack = new ArrayDeque<>();
        int index = 0;

        for (int in : putIn) {
            stack.push(in);
            while (index < takeOut.length && !stack.isEmpty() && takeOut[index] == stack.peek()) {
                stack.pop();
                index++;
            }
        }

        return index == takeOut.length - 1;

    }

}
